# -*- ecoding: utf-8 -*-
# @Author: Wick
# @Time: 2024-02-25 15:05

# 1、多个缺省参数的传递练习，练习多个缺省参数

def person(name, gender=True, height=170, weight=60):
    if gender == True:
        print(f"我是一个男生，我叫{name}，身高{height}，体重{weight}")
    else:
        print(f'我是一个女生，我叫{name}，身高{height}，体重{weight}')
person('小明')
person('小红', False, 160, 50)
person('小美', gender=False, height=165, weight=45)

# 2、多值参数练习，元组，字典的传参拆包练习

def demo1(num, *args, **kwargs):
    print(num)
    print(args)
    print(kwargs)
def demo(num, *args, **kwargs):
    demo1(num, *args, **kwargs)
demo(1, 2, 3, 4, 5, name="小明", age=18, gender=True)

#3.设计一个类，实例化1个对象，会实现下面两种行为
"""
需求
•一只 黄颜色 的 狗狗 叫 大黄
•具有  汪汪叫 行为
•具有  摇尾巴 行为
"""

class Dog:
    def __init__(self, name, color):
        self.name = name
        self.color = color

    def bark(self):
        print('汪汪叫')

    def wag(self):
        print("摇尾巴")

    def __str__(self):
        return f'这条狗的名字叫做{self.name}，颜色是{self.color}'

dahuang = Dog('大黄', '黄色')
dahuang.bark()
dahuang.wag()
print(dahuang)

#4.练习__init__，__str__还有__del__

class Car:
    def __init__(self, name, color, price):
        self.name = name
        self.color = color
        self.price = price
        self.fix_time = 5

    def __str__(self):
        return f'{self.name}的颜色是{self.color}，价格是{self.price}'

    def fix(self):
        self.fix_time += 1

    # def __del__(self):
    #     print(f'维修次数为{self.fix_time}次')

bi_ya_di = Car('比亚迪', '黑色', '100000')
bi_ya_di.fix()
print(bi_ya_di)

# 5.练习房子-家具类设计，感受类的设计的先后顺序
class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return f"{self.name}占地{self.area}"


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []

    def __str__(self):
        # Python 能够自动的将一对括号内部的代码连接在一起
        return ("户型：%s\n 总面积：%.2f[剩余：%.2f]\n 家具：%s"
                % (self.house_type, self.area,
                   self.free_area, self.item_list))

    def  add_item(self, item:HouseItem):
        #判断剩余面积是否还可以放家具
        if self.free_area >= item.area:
            self.item_list.append(item.name)
            self.free_area -= item.area
        else:
            print("空间不够，无法再放家具")

bed = HouseItem("席梦思", 4)
chest = HouseItem("衣柜", 2)
table = HouseItem("桌子", 1.5)

print(bed)

print("-"*50)
house = House("两室一厅", 60)
print(house)
house.add_item(bed)
print(house)
house.add_item(chest)
print(house)

# 6.练习私有属性和私有方法
class Women:
    def __init__(self, name):
        self.name = name
        self.__age = 23

    def manager(self):
        print(f'{self.name}的年龄是{self.__age}')

    def __secret(self):
        print(f'{self.name}喜欢下围棋')

    def boyfriend(self):
        self.__secret()

xiao_hong = Women('小红')
xiao_hong.manager()
xiao_hong.boyfriend()

# 7、练习继承、使用super调用父类方法，多重继承练习
class Horse:
    def run(self):
        print('我可以跑')

class Donkey:
    def load(self):
        print('我可以载货')

class BaiLong(Horse):
    def run(self):
        print('我可以再天上跑')
        super().run()

bai_long = BaiLong()
bai_long.run()

class Mule(Horse, Donkey):
    def endure(self):
        print('我耐力好')

luozi = Mule()
luozi.endure()
luozi.run()